package stackoverflow.domain.user;

import java.util.HashSet;
import java.util.Set;

public class UserUtility {

	public static User createNewUser(String name, String password) {
		User.UserBuilder userBuilder = new User.UserBuilder()
				.name(name)
				.password(password)
				.activityStatus(true)
				.roles(
						UserUtility
								.createUserRoles(new User.UserRole[] { User.UserRole.User }));
		return userBuilder.build();
	}

	public static User createNewAdmin(String name, String password) {
		User.UserBuilder userBuilder = new User.UserBuilder().name(name)
				.password(password).activityStatus(true).roles(
						UserUtility.createUserRoles(new User.UserRole[] {
								User.UserRole.User, User.UserRole.Moderator,
								User.UserRole.Admin }));
		return userBuilder.build();
	}

	public static User createNewModerator(String name, String password) {
		User.UserBuilder userBuilder = new User.UserBuilder().name(name)
				.password(password).activityStatus(true).roles(
						UserUtility.createUserRoles(new User.UserRole[] {
								User.UserRole.User, User.UserRole.Moderator }));
		return userBuilder.build();
	}

	public static Set<User.UserRole> createUserRoles(User.UserRole... roles) {
		Set<User.UserRole> userRoles = new HashSet<User.UserRole>();
		for (User.UserRole userRole : roles) {
			userRoles.add(userRole);
		}
		return userRoles;
	}
}
